#!/usr/bin/env python
# encoding: utf-8
# @author: liusir
# @file: config_utils.py
# @time: 2021/6/27 3:20 下午

import os
import configparser


class ConfigUtils:
    def __init__(self,config_file_path ):
        self.cfg_path = config_file_path
        self.cfg = configparser.ConfigParser()
        self.cfg.read( self.cfg_path )

    def read_value(self,section,key):
        value = self.cfg.get( section , key  )
        return value

    def write_value(self,section,key,value):
        self.cfg.set(section,key,value)
        config_file_obj = open( self.cfg_path ,'w')
        self.cfg.write( config_file_obj )
        config_file_obj.flush()
        config_file_obj.close()

if __name__=='__main__':
    config_utils = ConfigUtils()
    print( config_utils.read_value( 'default','HOSTS' ) )
    config_utils.write_value('default','token_value','6666')

